package com.itheima.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.ReportDao;
import com.itheima.service.MemberService;
import com.itheima.service.OrderService;
import com.itheima.service.ReportService;
import com.itheima.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportDao reportDao;
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
  //  <!--根据日期统计会员数，统计指定日期之前的会员数-->
    @Override
    public List<Integer> findByTime(List<String> list) {
        List<Integer> countlist=new ArrayList<>();
        if (list!=null&&list.size()>0){
            for (String s : list) {
                s=s+".31";
                int count=reportDao.findByTime(s);
                countlist.add(count);
            }
        }
        return countlist;
    }
    //      查询所有表中数据
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
       Map<String,Object> map= new HashMap<>();
        //                     reportDate:null, 今日日期
            String reportDate= DateUtils.parseDate2String(new Date());
            map.put("reportDate",reportDate);


            //                    todayNewMember :0, 今日新增会员数
            int todayNewMember=memberDao.findByTime(reportDate);
            map.put("todayNewMember",todayNewMember);


            //                    totalMember :0,   全部成员数
           int totalMember=memberDao.findAllCount();
           map.put("totalMember",totalMember);


            //                    thisWeekNewMember :0,本周新增会员数
            //先获取本周一的日期,
            String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
           int thisWeekNewMember= memberDao.findByTime(thisWeekMonday);
           map.put("thisWeekNewMember",thisWeekNewMember);


            //                    thisMonthNewMember :0,本月新增会员数
            String thisMonthOneDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
           int thisMonthNewMember = memberDao.findByTime(thisMonthOneDay);
           map.put("thisMonthNewMember",thisMonthNewMember);


            //                    todayOrderNumber :0,今天预约人数
            int todayOrderNumber=orderDao.findByTime(reportDate);
            map.put("todayOrderNumber",todayOrderNumber);


            //                    todayVisitsNumber :0,今天到诊人数
           int todayVisitsNumber=orderDao.findByTimeAndDZ(reportDate);
           map.put("todayVisitsNumber",todayVisitsNumber);


            //                    thisWeekOrderNumber :0,本周预约人数
          int thisWeekOrderNumber=orderDao.findByTime(thisWeekMonday);
          map.put("thisWeekOrderNumber",thisWeekOrderNumber);


            //                    thisWeekVisitsNumber :0,本周到诊人数
            int thisWeekVisitsNumber=orderDao.findByTimeAndDZ(thisWeekMonday);
            map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);


            //                    thisMonthOrderNumber :0,本月预约人数
            int thisMonthOrderNumber=orderDao.findByTime(thisMonthOneDay);
            map.put("thisMonthOrderNumber",thisMonthOrderNumber);


            //                    thisMonthVisitsNumber :0,本月到诊人数
            int thisMonthVisitsNumber=orderDao.findByTimeAndDZ(thisMonthOneDay);
            map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);


//           hotSetmeal :[
//          {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
//           name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
            List<Map<String,Object>> hotSetmeal=orderDao.hotSetmeal();
            map.put("hotSetmeal",hotSetmeal);
        return map;
    }
    //获取预约报表数据每日预约数 每日到诊数
    @Override
    public Map<String, Object> getOrderReport() throws Exception {
//        String reportDate= DateUtils.parseDate2String(new Date());
//        int orderCount = orderDao.findByTime(reportDate);
//        orderDao.
        return null;
    }


}
